/*
 * GLLib.h
 *
 *	Interface for a potpourri of OpenGL functionality and initialization.
 *	Creates the GL namespace, in which all OpenGL functionality will reside
 * 
 *  Created on: May 2, 2013
 *      Author: zapmunk
 */

#pragma once

#include "headerstop.h"

#include "Texture.h"

#include "GL_CALLBACKS.h"
#include "GL_EXTENSIONS.h"

namespace GL {
	#define init(name, ret, args) typedef ret (APIENTRY* name ## _func)args;\
										extern name ## _func name
	_GL_CALLBACKS
	#define init_adapt(adapter) adapter
	_GL_EXTENSIONS
	#undef init
	#undef init_adapt
	//Creates the rendering context and loads callbacks
	bool initGL(SDL_Window* window, SDL_GLContext* context);


	//Draws a Texture tex at position (x, y) with color rgb
	bool drawTexture(const Texture& tex, uint x, uint y, GLfloat r = 1, GLfloat g = 1, GLfloat b = 1, GLfloat a = 1);
	//Draws a portion of a Texture tex defined by src at position (x, y) with color rgb
	bool drawTexture(const Texture& tex, const SDL_Rect& src, uint x, uint y, GLfloat r = 1, GLfloat g = 1, GLfloat b = 1, GLfloat a = 1);
	//Draws a portion of a Texture tex defined by src stretched to fill the rectangle dest with color rgb
	bool drawTexture(const Texture& tex, const SDL_Rect& src, const SDL_Rect& dest, GLfloat r = 1, GLfloat g = 1, GLfloat b = 1, GLfloat a = 1);

	//Rotates the scene around a given point, for convenience
	#define rotateAround(theta, x, y) {\
		GL::glTranslatef(x, y, 0);\
		GL::glRotatef(theta, 0, 0, 1.0);\
		GL::glTranslatef(-(x), -(y), 0);\
	}
};

#undef _GL_CALLBACKS
#undef _GL_EXTENSIONS
